package com.herench.bs.handler;


import com.herench.bs.agent.IInHosAgent;
import com.herench.bs.annotation.Handler;
import com.herench.bs.support.AbstractMessageHandler;
import com.herench.bs.support.RequestMessage;
import com.herench.bs.support.ResponseMessage;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import java.util.Map;


/**
 * Created by Liuxh on 2019/3/26.
 */
@Component
@Handler(code = "200104",name="患者入院申请取消：DoCancelAppointInHos()")
public class DoCancelAppointInHosHandler extends AbstractMessageHandler {

    @Override
    protected ResponseMessage innerHandler(RequestMessage requestMessage) throws Exception {
        ResponseMessage responseMessage = new ResponseMessage(requestMessage.getId());

        // **************** 微信前端传入的参数 ******************************************* Start
        // 系统编码：微信前端区分医院用
        String channelCode = requestMessage.getArgsPropertyStringValue("sysCode");
        // 身份证号
        String idNo = requestMessage.getArgsPropertyStringValue("idNo");
        // 患者ID
        String patientId = requestMessage.getArgsPropertyStringValue("patientId");
        // 入院申请ID
        String hosAppId = requestMessage.getArgsPropertyStringValue("hosAppId");
        Assert.notNull(hosAppId, "hosAppId 不可为空！");

        // 微信公众号注册手机号：微信消息推送用
        String wxUserMobile = requestMessage.getArgsPropertyStringValue("wxUserMobile");
        // 患者姓名：微信消息推送用
        String patientName = requestMessage.getArgsPropertyStringValue("patientName");
        // 预约时间：微信消息推送用
        String appointmentTime = requestMessage.getArgsPropertyStringValue("appointmentTime");
        // **************** 微信前端传入的参数 ******************************************* End

        // 医院代码：微信后端区分医院用
        String hospitalCode = getCleverClinicContext().getHospitalCodeByChannelCode(channelCode);

        // 获取Bean信息
        IInHosAgent inHosAgent = getCleverClinicContext().getApplicationContext().getBean(IInHosAgent.class);
        // 设定入参
        Map<String, Object> res = inHosAgent.doCancelAppointInHos(channelCode, hospitalCode, idNo, patientId, hosAppId, wxUserMobile, patientName, appointmentTime);

        // 设置应答信息
        responseMessage.setData(res);
        getPropertiesFromInvokerResultMap(responseMessage, res);

        return responseMessage;
    }
}
